home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / DVIM72-M / MAC_PRIN.C < prev    next >
Text File  |  1990-05-18  |  4KB  |  134 lines

  1. /* Code adapted from Tech Note 95. */
  2.  
  3. #include <MacProto.h>
  4.  
  5. /* NOTE: Apple reserves the top half of the screen (where the current DITL
  6.     items are located). Applications may use the bottom half of the screen
  7.     to add items, but should not change any items in the top half of the
  8.     screen.  An application should expand the print dialogs only as much
  9.     as is absolutely necessary.
  10. */
  11.  
  12. /* Note: A global search and replace of 'Job' with 'Stl' will produce 
  13.     code that modifies the style dialogs */
  14. #include <PrintTraps.h>
  15. #define nil 0L
  16.  
  17. #include "mac_printing.h"
  18. #define PRJOB_DITL_ID        2323
  19. #define EDIT_ITEM        2    /* Second new dialog item is editable text. */
  20.  
  21. static TPPrDlg PrtJobDialog;        /* pointer to job dialog */
  22.  
  23. /*    This points to the following structure:
  24.     
  25.       struct { 
  26.           DialogRecord    Dlg;          (The Dialog window)
  27.           ProcPtr        pFltrProc;    (The Filter Proc.)
  28.           ProcPtr        pItemProc;    (The Item evaluating proc. --                             we'll change this)
  29.           THPrint        hPrintUsr;    (The user's print record.)
  30.           Boolean        fDoIt;    
  31.           Boolean        fDone;    
  32.               (Four longs -- reserved by Apple Computer)
  33.           long            lUser1;         
  34.           long            lUser2;        
  35.           long            lUser3;    
  36.           long            lUser4;        
  37.    } TPrDlg; *TPPrDlg;          
  38. */
  39.  
  40.  
  41.  
  42. /*    Declare ╘pascal╒ functions and procedures */
  43. pascal TPPrDlg MyJobDlgInit(THPrint hp);    /* Our extention to PrJobInit */
  44. pascal void MyJobItems(TPPrDlg d, int item); /* Our modal item handler */
  45.  
  46. long prFirstItem;                /* save our first item here */
  47. long prPItemProc;            /* we need to store the old itemProc here */
  48.  
  49. /*-----------------------------------------------------------------------*/
  50.  
  51. OSErr Special_job_dialog( THPrint hPrintRec )
  52. /* Input: a handle to a print record, already allocated and modified.
  53.    Output:  a string containing the "other commands" and an error code. 
  54. */
  55. {
  56.     PrValidate(hPrintRec);
  57.     if (PrError() != noErr)
  58.         return PrError();        
  59.  
  60.     /* call PrJobInit to get pointer to the invisible job dialog */
  61.     PrtJobDialog = PrJobInit(hPrintRec);
  62.     if (PrError() != noErr)
  63.         return PrError();        
  64.  
  65.     
  66.     if (!PrDlgMain(hPrintRec, &MyJobDlgInit))    /* this line does all the 
  67.     stuff */
  68.         return Cancel;
  69.  
  70.     if (PrError() != noErr)
  71.         return PrError();        
  72.     else
  73.         return( noErr );
  74. /* that's all for now */
  75.         
  76. } /* Special_job_dialog */
  77.  
  78. /*------------------------------------------------------------------------*/
  79.  
  80. pascal TPPrDlg MyJobDlgInit (hPrint)
  81. THPrint hPrint;
  82. /* this routine appends items to the standard job dialog and sets up the
  83.     user fields of the printing dialog record TPRDlg 
  84.     This routine will be called by PrDlgMain */
  85. {
  86.     short        firstItem;        /* first new item number */
  87.     
  88.     short        itemType;        /* needed for GetDItem/SetDItem call */
  89.     Handle    itemH;
  90.     Rect        itemBox;
  91.     
  92.     firstItem = AppendDITL ((DialogPtr)PrtJobDialog,
  93.         PRJOB_DITL_ID); /*call routine to do this */
  94.     
  95.     prFirstItem = firstItem; /* save this so MyJobItems can find it */
  96.     
  97. /* Now comes the part where we patch in our item handler.  We have to save
  98.     the old item handler address, so we can call it if one of the     standard items is hit, and put our item handler's address
  99.     in pItemProc field of the TPrDlg struct
  100. */
  101.  
  102.     prPItemProc = (long)PrtJobDialog->pItemProc;
  103.     
  104. /* Now we'll tell the modal item handler where our routine is */
  105.     PrtJobDialog->pItemProc = (ProcPtr)&MyJobItems;
  106.     
  107. /* PrDlgMain expects a pointer to the modified dialog to be returned.... */
  108.     return PrtJobDialog;
  109.     
  110. } /*myJobDlgInit*/
  111.  
  112.  
  113. /*-----------------------------------------------------------------------*/
  114.  
  115. /* here's the analogue to the SF dialog hook */
  116.  
  117. pascal void MyJobItems(theDialog,itemNo)
  118. TPPrDlg    theDialog;
  119. short     itemNo;
  120. {    
  121.     short        itemType;        /* needed for GetDItem/SetDItem call */
  122.     Handle        itemH;
  123.     Rect        itemBox;
  124.     
  125.     if (itemNo == 1) /* OK */
  126.     {
  127.         GetDItem( (DialogPtr)theDialog, EDIT_ITEM + prFirstItem - 1,
  128.             &itemType, &itemH, &itemBox );
  129.         GetIText( itemH, g_other_commands );
  130.     }
  131.     CallPascal( theDialog, itemNo, prPItemProc );
  132. } /* MyJobItems */
  133.  
  134.